/*
 * Copyright 2011 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package it.davial.mgwt.client.activities.visit;

import it.davial.mgwt.client.Visit;
import it.davial.mgwt.client.activities.BaseViewImpl;
import it.davial.mgwt.client.resources.ResourceAware;
import it.davial.mgwt.client.ui.widget.VisitCellList;
import it.davial.mgwt.client.ui.widget.search_form.SearchForm;

import java.util.Date;
import java.util.List;

import com.googlecode.mgwt.dom.client.event.tap.HasTapHandlers;
import com.googlecode.mgwt.ui.client.widget.buttonbar.ButtonBar;
import com.googlecode.mgwt.ui.client.widget.buttonbar.ComposeButton;
import com.googlecode.mgwt.ui.client.widget.buttonbar.SearchButton;

/**
 * Sample implementation of {@link VisitView}.
 */
public class VisitViewImpl extends BaseViewImpl implements ResourceAware,VisitView {

	private SearchButton bSearch;
	private ComposeButton bEdit;
	private VisitCellList list;
	private SearchForm searchForm;

	public VisitViewImpl() {
		bSearch = new SearchButton();
		bEdit = new ComposeButton();
		searchForm = new SearchForm();
		ButtonBar bb = new ButtonBar();
		bb.setStyleName(mainCss.getMainCss().buttonBar());
		bb.add(bSearch);
		bb.add(bEdit);
		
		headerPanel.setRightWidget(bb);
		scrollPanel.setScrollingEnabledX(false);
		
		main.remove(scrollPanel);
		main.add(searchForm);	
		
	}
	@Override
	public HasTapHandlers getEditButton() {
		return bEdit;
	}
	@Override
	public HasTapHandlers getSearchButton() {
		return bSearch;
	}
	@Override
	public void setVisits(List<Visit> patients) {
		list.render(patients);
		
	}
	@Override
	public void setVisitCellList(VisitCellList list) {
		this.list = list;
		main.add(scrollPanel);
		scrollPanel.setWidget(list);
		
	}
	@Override
	public String getSurname() {
		return searchForm.getSurname();
	}
	@Override
	public Date getDate() {
		return searchForm.getDate();
	}

}
